<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
    <title>
      基本信息
    </title>
</head>

<body>

<div id="wrapper">
    <div class="gray-bg">
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="tabs-container">
                        <ul class="nav nav-tabs">
                            <li class="active"><a  href="javascript:void(0)">基本信息</a></li>
                            <c:if test="${infoOnly!='true'}">
                                <li class=""><a  href="${ctx}/medical/sign/spck/list?id=${data.signId}">服务包</a></li>
                                <li class=""><a  href="${ctx}/medical/record/list_ecn?ecn=${ecn}&signId=${data.signId}">服务记录</a></li>
                                <li class=""><a  href="${ctx}/medical/sign/deal/edit?id=${data.signId}">签约协议</a></li>
                            </c:if>
                        </ul>
                    </div>
                    <div class="ibox float-e-margins tab-cnt">
                        <div class="ibox-content">
                            <form method="get" data-ajax="${ctx}/medical/sign/list" action="${ctx}/medical/sign/${method}"  class="form-horizontal" id="user_form">
                                <input  type="hidden" id="signId" name="signId" value="${data.signId}"/>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>姓名</label>
                                    <div class="col-sm-3"><input id="name" type="text" class="form-control" placeholder="姓名" value="${data.username}" name="username" required readonly></div>
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>身份证</label>
                                    <div class="col-sm-3"><input id="idcard" type="text" class="form-control"  placeholder="身份证" value="${data.idcard}" name="idcard" required readonly></div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>性别</label>
                                    <div class="col-sm-3"><input id="sex" type="text" class="form-control" placeholder="性别" value="${data.sex}" name="sex" required readonly></div>
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>年龄</label>
                                    <div class="col-sm-3"><input id="age" type="text" class="form-control" placeholder="年龄" value="${data.age}" name="age" required readonly></div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>手机号</label>
                                    <div class="col-sm-3"><input id="mobile" type="text" class="form-control" placeholder="手机号" value="${data.mobile}" name="mobile" required readonly></div>
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>街道</label>
                                    <div class="col-sm-3"><input id="street" type="text" class="form-control" placeholder="街道" value="${data.street}" name="street" required readonly></div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>签约团队</label>
                                    <div class="col-sm-3"><input id="team" type="text" class="form-control" placeholder="签约团队" value="${data.teamName}" name="teamName" required readonly></div>
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>签约时间</label>
                                    <div class="col-sm-3"><input id="time" type="text" class="form-control" placeholder="签约时间" value="1年" required readonly></div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>签约时间</label>
                                    <div class="col-sm-3">
                                        <div class="input-group date" datepicker>
                                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span><input type="text" id="signTime" readonly name="signTime" value="<fmt:formatDate value="${data.signTime}" pattern="yyyy-MM-dd"/>" class="form-control" required>
                                        </div>
                                    </div>
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>签约结束</label>
                                    <div class="col-sm-3">
                                        <div class="input-group date" datepicker>
                                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span><input type="text" id="expireTime" readonly name="expireTime" value="<fmt:formatDate value="${data.expireTime}" pattern="yyyy-MM-dd"/>" class="form-control" required>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">备注</label>
                                    <div class="col-sm-8"><textarea class="form-control" name="memoResident" style="height: 100px;">${data.memoResident}</textarea></div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">人群分类</label>
                                    <div class="col-sm-9">
                                    <c:forEach items="${kv}" var="items" >
                                        <label class="m-t-sm7">
                                            <input type="checkbox" class="check-style" id="${items.key}" name="key" onclick="isCheck(this)">
                                        </label>
                                        <span>${items.value}</span>
                                    </c:forEach></div>
                                </div>


                                <div class="hr-line-dashed"></div>
                                <c:if test="${isshow==11}">
                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-2">
                                            <button class="btn" type="button" onclick="save()">确定</button>
                                        </div>
                                    </div>
                                </c:if>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="${ctx}/static/inspinia/js/plugins/layer/layer.js"></script>
<script>
    var select_item_ids = [];
    $(document).ready(function() {
        init();

        var kvjson = JSON.parse('${kvjson}');
        if (kvjson.length > 0){
            for (i in kvjson) {
                if(kvjson[i].ischeck == 1){
                    $("input[id="+kvjson[i].key+"]").prop("checked", true);
                }
            }
        }
    });

    function init() {
        $("input[name='key']:checked").each(function(){
            $(this).attr("checked",false);
        });
        select_item_ids=[];
    }

    function addcheck(id ){
        if(id == "01"){
            $("input[id="+'02'+"]").prop("checked", false);
            $("input[id="+'03'+"]").prop("checked", false);
            $("input[id="+'10'+"]").prop("checked", false);
        }else if(id == "02"){
            $("input[id="+'01'+"]").prop("checked", false);
            $("input[id="+'03'+"]").prop("checked", false);
            $("input[id="+'10'+"]").prop("checked", false);
        }else if(id == "03"){
            $("input[id="+'02'+"]").prop("checked", false);
            $("input[id="+'01'+"]").prop("checked", false);
            $("input[id="+'10'+"]").prop("checked", false);
        }else if(id == "10"){
            init();
            $("input[id="+'10'+"]").prop("checked", true);
        }else if(id == "11"){
            $("input[id="+'12'+"]").prop("checked", false);
            $("input[id="+'10'+"]").prop("checked", false);
        }else if(id == "12"){
            $("input[id="+'11'+"]").prop("checked", false);
            $("input[id="+'10'+"]").prop("checked", false);
        }else {
            $("input[id="+'10'+"]").prop("checked", false);
        }
    }

    function save(){
        select_item_ids = [];
        $("input[name='key']:checked").each(function(){
            console.log($(this).attr('id'));
            select_item_ids.push($(this).attr('id'));
        });

        if(select_item_ids.length == 0){
            layer.msg('请选择人群分类');
            return ;
        }

        var siid = $("#signId").val();
        var memo = $("textarea[name='memoResident']").val();
        $.ajax({
            method: "POST",
            url: "${ctx}/medical/sign/add/type",
            data: {
                type:select_item_ids.join(","),
                signId:siid,
                memo:memo

            },
            dataType: "json",
            async: false,
            success: function(response) {
                if (response.code == 0) {
//                    parent.frames[0].refest();
                    window.parent.refest();
                    layer.msg('已保存');
                }else{
                    layer.msg('错误');
                }
            }
        });
    }


    function isCheck(self){
        var checked = $(self).is(':checked');
        var id = $(self).attr('id');
        if (checked){
            addcheck(id);
        }
        console.log(select_item_ids)
    }

</script>
</body>
</html>
